package com.yucc.girlimage.io.upyun;


import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.yucc.girlimage.BuildConfig;
import com.yucc.girlimage.util.ImageWorker.ImageWorkerAdapter;

/**
 * 扩展的图片下载适配器
 * @author yucc
 *
 */
public class ExtImageWorkerAdapter extends ImageWorkerAdapter implements Parcelable {
	public static final String HTTP_URL_PREFIX = "http://yucc-girls.b0.upaiyun.com/" ;
	private static final String THUMB_NAME = "1" ;
	private ArrayList<FolderItem> mList ;
	private boolean isThumb ;
	
	public ExtImageWorkerAdapter(ArrayList<FolderItem> list) {
		this.mList = list ;
	}

	public void setThumb(boolean isThumb) {
		this.isThumb = isThumb;
	}

	public void setList(ArrayList<FolderItem> mList) {
		this.mList = mList;
	}
	
	public ArrayList<FolderItem> getList(){
		return mList ;
	}
	
	@Override
	public Object getItem(int num) {
		String temp = null ;
		final FolderItem item = mList.get(num) ;
		if(isThumb) temp = HTTP_URL_PREFIX + item.path + "/" + item.name +"!" +THUMB_NAME;
		else temp = HTTP_URL_PREFIX + item.path + "/" + item.name ;
		if(BuildConfig.DEBUG) Log.d("temp", "getItem=" + temp) ;
		return temp ;
	}

	@Override
	public int getSize() {
		return mList != null ? mList.size() : 0;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeTypedList(mList) ;
		if(isThumb) dest.writeInt(1) ;
		else dest.writeInt(0) ;
	}
	
	public static final Parcelable.Creator<ExtImageWorkerAdapter> CREATOR = new Parcelable.Creator<ExtImageWorkerAdapter>() {
		// 重写Creator

		public ExtImageWorkerAdapter createFromParcel(Parcel source) {
			ArrayList<FolderItem> list = new ArrayList<FolderItem>() ;
			source.readTypedList(list, FolderItem.CREATOR) ;
			ExtImageWorkerAdapter item = new ExtImageWorkerAdapter(list) ;
			item.setThumb(source.readInt() == 1 ? true : false) ;
			return item ;
		}
		public ExtImageWorkerAdapter[] newArray(int size) {
			// TODO Auto-generated method stub
			return null;
		}
	} ;
	
}
